package generateNodes;

import java.util.ArrayList;
import java.util.Random;

import networkInterface.*;

import object.Node;
import util.NodeUtil;
import util.Settings;

public class GenerateRandomClusters extends GenerateNodeBase {
	private int clusterSize = 5;
	private int x;
	private int y;
	@Override
	public Node genNodes(ArrayList<Node> nodes, int xSize, int ySize){
		if(r==null)
			r = new Random(Settings.getInstance().getSeed().hashCode());

		if(created%clusterSize == 0){
			x = Math.abs((r.nextInt()%xSize-50)+25);
			y = Math.abs((r.nextInt()%ySize-50)+25);
		}
		
		int curX=-100, curY=-100;
		Node n;
		do {
			curX = x + r.nextInt()%45;
			curY = y + r.nextInt()%35;
			n = new Node(curX, curY);
		} while(curX<=0 || curY<=0 || curX>=xSize || curY>=ySize || !NodeUtil.isValidNodeLocation(n, nodes));
		
		if(r.nextInt()%(10) == 0){
			//4g tower
			if((int)(r.nextInt()%3) == 0){
				n.addNetworkInterface(new Tower3GInterface(n));
			} else {
				n.addNetworkInterface(new Phone3GInterface(n));
				n.addNetworkInterface(new SimpleMediumWifiInterface(n));
				if(r.nextInt()%2 == 0)
					n.addNetworkInterface(new SimpleSmallWifiInterface(n));
			}
			
		} else {
			//wifi node
			n.addNetworkInterface(new SimpleSmallWifiInterface(n));
			n.addNetworkInterface(new SimpleSmallWifiInterface(n));
			if(r.nextInt()%3 == 0)
				n.addNetworkInterface(new SimpleSmallWifiInterface(n));
			if(r.nextInt()%4 == 0)
				n.addNetworkInterface(new SimpleMediumWifiInterface(n));
			if(r.nextInt()%14 == 0)
				n.addNetworkInterface(new Phone3GInterface(n));
		}
		nodes.add(n);
		created++;
		return n;
		

//			nodes.add(n);
//		}
	}

}
